package com.gene.service.impl;

import com.gene.mapper.UserCollectionMapper;
import com.gene.pojo.UserCollection;
import com.gene.pojo.UserCollectionExample;
import com.gene.pojo.entity.Favorite;
import com.gene.service.IUserCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class UserCollectionServiceImpl implements IUserCollectionService {
    @Autowired
    private UserCollectionMapper userCollectionMapper;


    @Override
    public List<Favorite> query(UserCollection userCollection) {
        List<Favorite> list=userCollectionMapper.query(userCollection.getUserId());

        return list;
    }

    @Override
    public Favorite selectId(UserCollection userCollection) {

        return userCollectionMapper.selectId(userCollection.getCollectionId());
    }

    @Override
    public boolean add(UserCollection userCollection) {
        userCollection.setCtime(new Date());
        int a=userCollectionMapper.insert(userCollection);
        if(a==1){
            return true;
        }
        return false;
    }

    @Override
    public boolean edit(UserCollection userCollection) {
        int a=userCollectionMapper.updateByPrimaryKeySelective(userCollection);
        if(a==1){
            return true;
        }
        return false;
    }

    @Override
    public boolean delete(UserCollection userCollection) {
        int a=userCollectionMapper.deleteByPrimaryKey(userCollection.getCollectionId());
        if(a==1){
            return true;
        }
        return false;
    }

    @Override
    public boolean enshrine(UserCollection userCollection) {
        UserCollectionExample example=new UserCollectionExample();
        UserCollectionExample.Criteria criteria = example.createCriteria();
        criteria.andUserIdEqualTo(userCollection.getUserId());
        criteria.andItemIdEqualTo(userCollection.getItemId());
        List<UserCollection> list = userCollectionMapper.selectByExample(example);
        if(list.size()>0){
            return true;
        }
        return false;
    }
}
